<?php

class Page {


    /* Utilities */
    
  
    
    /* Check if user is logged in */
    public function checkLogin($db) {
    }
    
    /* Call this method to start generating the page header and footer */
    public function generate() {
        $this->displayHeader();
        register_shutdown_function(array($this, 'displayFooter'));// Call the displayFooter function at the end of the page (but not now).
    }
    
    /* display functions */
    public function displayHeader() {
        echo '<!doctype html>';
        
        ?>
        <html>
            <head>
                <meta charset="UTF-8">
                <title>My Catalog</title>
            </head>
            <body>
                <header>
                    <h1>My Catalog</h1>
<?php if(isSet($_SESSION['login'])) { ?>
				 

                    <div id="search-box">
                        <form action="index.php" method="GET">
                            <input type="text" name="search" placeholder="Search items..." value="<?php echo $this->getPageParam('search'); ?>">
                            <input type="submit" value="Search">
                        </form>
                    </div><nav id="main-menu">
						<li><a href="logout.php">Logout</a></li>
					</nav>
				<?php } else { ?>


		<form id="login-box" action="index.php" method="post">
		 <input type="text" name="login" placeholder="Login">
		 <input type="password" name="password" placeholder="Password">
		<input type="submit" value="Login">
					</form> <?php } ?>

                </header>
        <?php

    }
public function checkLogin($db) { 
		if(isSet($_POST['login']) && isSet($_POST['password'])) {
			if($db->checklogin($_POST['login'], $_POST['password'])) {
				$_SESSION['login'] = true;
			}
		}
		return isSet($_SESSION['login']);
	}

    public function displayFooter() {
    
        ?>
            </body>
        </html>
        <?php

    }

    
   
session_start();
$page = new Page();


require('db.php');

/* For checking login */
$page->checkLogin($db);

/* For searching */
$searchText = NULL;

/* get items */
$items = array();

/* Start generating the page header */
$page->generate();

/* display content */
$page->displayAllItems($items);


